﻿Imports System.IO
Imports System.Net
Imports System.Text

Module Api
    Public Async Function SpacesPost(URL As String, Optional body As String = "") As Task(Of String)
        Dim wc As New WebClient
        wc.Encoding = Encoding.UTF8
        wc.Headers.Add(HttpRequestHeader.ContentType, "application/x-www-form-urlencoded")
        wc.Headers.Add(HttpRequestHeader.Cookie, My.Settings.Cookie)
        wc.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0")
        Dim r = Await wc.UploadStringTaskAsync(URL, body)
        Dim Cookie1() As String = wc.ResponseHeaders.GetValues("Set-Cookie")
        Dim s As String
        For Each i In Cookie1
            s = s & i
        Next
        If s <> My.Settings.Cookie Then
            My.Settings.Cookie = s
            My.Settings.Save()
        End If
        Return r
    End Function

End Module
